(function(){

    // 点击绑定   
    $(".wx_box").on("click",".bind_wxbtn, .bangding",function(){ 
        $('.alert-over-box').fadeIn(); 
        $('.bind-ever').css('display', "block");
        $('.bind-success').css('display', "none"); 
        check_wechat_bind();
    })


    //点击解绑
    $(".wx_box").on("click",".untie_bind_wxbtn, .jiebang",function(){  
        $.ajax({
            url : "/wechat/out_bind",
            type : 'get',
            success : function(data){
                data = eval("(" + data + ")"); 
                if(data.code == 0){
                    layer.msg("取消绑定成功");  
                    setTimeout(function(){
                        window.location.reload()  
                    },2000)  
                }
            },error:function(){ 
                //error
            }
        });
    })
      
    // 点击取消 遮罩层关闭
    $('.alert-over-box').off('click','.closeover').on('click','.closeover',function(){  
        clearInterval(timeInter); 
        var $t=$(this);   
        $t.parents('.alert-over-box').fadeOut();  
    })

    // 点击继续 
    $(".continu-link").bind("click",function(){   
        $(".alert-over-box").hide(); 
        clearInterval(timeInter);
    })   
    
    //微信绑定 3天不显示 
    $("#no-show").bind("click",function(){
        $.ajax({
            url : "/wechat/set_time_expire",
            type : 'get',
            success : function(data){
                data = eval("(" + data + ")"); 
                if(data.code == 0){
                    clearInterval(timeInter);
                    $('.alert-over-box').fadeOut();  
                    setCookie('is_onelogin', null, {
                        expire:-1, path: '/',domain:'saikr.com'
                    });   
                }
            },error:function(){ 
                //error
            }
        });
    });

})()
var timeInte; 

function check_wechat_bind(){
    var url = '/wechat/check_wechat_bind';
    timeInter = setInterval(function () {
        $.ajax({
            url : url,
            type : 'get',
            success : function(data){
                data = eval("(" + data + ")"); 
                if(data.code == 0){//绑定成功  
                    $('.bind-ever').css('display', "none");
                    $('.bind-success').css('display', "block"); 
                    $(".wx_box").empty();
                    var jiebang = '<span class="sk-btn bind_all jiebang">解 绑</span>';
                    $(".wx_box").append(jiebang);
                    $(".wxbing_i").addClass("active");
                    $(".weixin_text").text("已绑定")
                    // 3秒消失
                    var wait=$(".time-num").text();
                    timer = setInterval(function(){
                        if(wait==0){
                            $(".alert-over-box").hide();   
                            clearInterval(timer); 
                            clearInterval(timeInter); 

                        }else{
                            wait--;
                            $(".time-num").text(wait); 
                        }
                    },1000);
                    
                }else if(data.code == 500){//未绑定  
                    $('.alert-over-box').fadeIn(); 
                }else if(data.code == 300){ 
                    layer.msg("已绑定其它帐号,请取关后重新操作~");  
                }else{
                    $('.alert-over-box').fadeIn(); 

                } 
            },error:function(){ 
                //error
            }
        }); 

    },5000) 
}

//设置cookie方法
function setCookie(c_name,value,json)
{
    var exdate=new Date();
    exdate.setTime(exdate.getTime()+json.expire*1000);
    document.cookie=c_name+ "=" +escape(value)+
    ((json.expire==null) ? "" : ";expires="+exdate.toGMTString())+";path="+json.path+";domain="+json.domain;
};

//获取cookie方法
function getCookie(c_name)
{
    var c_start,c_end;
    if (document.cookie.length>0)
    {
        c_start=document.cookie.indexOf(c_name + "=");
        if (c_start!=-1)
        { 
            c_start=c_start + c_name.length+1 
            c_end=document.cookie.indexOf(";",c_start)
            if (c_end==-1) c_end=document.cookie.length
            return unescape(document.cookie.substring(c_start,c_end))
        } 
    }
    return ""
}; 

//清除cookie
function clearCookie(name) {
    setCookie(name, "", {expire:-1,path:'/',domain:'saikr.com'});
}